#ifndef _MY_ISTREAM_ITERATOR_TCC_
#define _MY_ISTREAM_ITERATOR_TCC_

template<typename T, typename CharT, typename Traits, typename Distance>
my_istream_iterator<T, CharT, Traits, Distance>::my_istream_iterator() {
	this->is = 0;
	data = (T*)::operator new (sizeof(T));
	eof = true;
}

template<typename T, typename CharT, typename Traits, typename Distance>
my_istream_iterator<T, CharT, Traits, Distance>::my_istream_iterator(istream_type& is) {
	this->is = &is;
	data = (T*)::operator new (sizeof(T));
	read();
}

template<typename T, typename CharT, typename Traits, typename Distance>
my_istream_iterator<T, CharT, Traits, Distance>::my_istream_iterator(const my_istream_iterator& orig) {
	is = orig.is;
	data = new T(*orig.data);
	eof = orig.eof;
}

template<typename T, typename CharT, typename Traits, typename Distance>
my_istream_iterator<T, CharT, Traits, Distance>::my_istream_iterator(istream_type* is, const T* data, const bool eof) {
	this->is = is;
	this->data = new T(*data);
	this->eof = eof;
}

template<typename T, typename CharT, typename Traits, typename Distance>
my_istream_iterator<T, CharT, Traits, Distance>::~my_istream_iterator() {
	delete data;
}

template<typename T, typename CharT, typename Traits, typename Distance>
const T my_istream_iterator<T, CharT, Traits, Distance>::operator * () {
	return *data;
}

template<typename T, typename CharT, typename Traits, typename Distance>
T* my_istream_iterator<T, CharT, Traits, Distance>::operator -> () {
	return data;
}

template<typename T, typename CharT, typename Traits, typename Distance>
const my_istream_iterator<T, CharT, Traits, Distance>& my_istream_iterator<T, CharT, Traits, Distance>::operator ++ () {
	read();
	return *this;
}

template<typename T, typename CharT, typename Traits, typename Distance>
my_istream_iterator<T, CharT, Traits, Distance> my_istream_iterator<T, CharT, Traits, Distance>::operator ++ (int) {
	my_istream_iterator<T, CharT, Traits, Distance> copy(is, data, eof);
	read();
	return copy;
}

template<typename T, typename CharT, typename Traits, typename Distance>
bool operator == (const my_istream_iterator<T, CharT, Traits, Distance>& lhs, const my_istream_iterator<T, CharT, Traits, Distance>& rhs) {
	return lhs.eof == rhs.eof;
}

template<typename T, typename CharT, typename Traits, typename Distance>
bool operator != (const my_istream_iterator<T, CharT, Traits, Distance>& lhs, const my_istream_iterator<T, CharT, Traits, Distance>& rhs) {
	return !operator == (lhs, rhs);
}

template<typename T, typename CharT, typename Traits, typename Distance>
void my_istream_iterator<T, CharT, Traits, Distance>::read() {
	eof = is->eof();
	is->operator >> (*data);
}

#endif

